package com.ikkong.sn.controller;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.ikkong.core.base.BaseController;
import com.ikkong.core.dao.Blade;
import com.ikkong.core.jfinal.ext.kit.JsonKit;
import com.ikkong.core.jfinal.ext.shiro.ClearShiro;
import com.ikkong.core.toolbox.Record;
import com.ikkong.system.controller.base.UrlPermissController;
import com.ikkong.sn.model.SnOrderInlog;
import com.ikkong.sn.service.SnOrderInlogService;
import com.ikkong.sn.service.impl.SnOrderInlogServiceImpl;
import org.beetl.sql.core.kit.StringKit;

/**
 * Generated by Blade.
 * 2019-04-25 21:36:08
 */
public class SnOrderInlogController extends UrlPermissController {
	private static String CODE = "snOrderInlog";
	private static String PERFIX = "sn_order_inlog";
	private static String LIST_SOURCE = "SnOrderInlog.list";
	private static String BASE_PATH = "/platform/snOrderInlog/";
	
	SnOrderInlogService service = new SnOrderInlogServiceImpl();
	
	public void index() {
		setAttr("code", CODE);
		render(BASE_PATH + "snOrderInlog.html");
	}

    @ClearShiro
	public void add() {
        String orderId = getPara("orderId");
        setAttr("orderId",orderId);
        setAttr("code", CODE);
		render(BASE_PATH + "snOrderInlog_add.html");
	}
	@ClearShiro
	public void edit() {
		String id = getPara(0);
		SnOrderInlog snOrderInlog = service.findById(id);
		setAttr("model", JsonKit.toJson(snOrderInlog));
		setAttr("orderlog",snOrderInlog);
		setAttr("id", id);
		setAttr("code", CODE);
		render(BASE_PATH + "snOrderInlog_edit.html");
	}

	public void view() {
		String id = getPara(0);
		SnOrderInlog snOrderInlog = service.findById(id);
		setAttr("model", JsonKit.toJson(snOrderInlog));
		setAttr("id", id);
		setAttr("code", CODE);
		render(BASE_PATH + "snOrderInlog_view.html");
	}

	@ClearShiro
	public void list() {
        String orderId = getPara("orderId");
        Map para = new HashMap();
        if(StringKit.isNotBlank(orderId)){
            para.put("orderId",orderId);
        }
        List<Map> select = Blade.dao().select("SnOrderInlog.list", Map.class, para);
        renderJson(Record.create().set("rows",select).set("records",select.size()));
	}
	@ClearShiro
	public void save() {
		SnOrderInlog snOrderInlog = mapping(PERFIX, SnOrderInlog.class);
        BigDecimal price = snOrderInlog.getPrice();
        snOrderInlog.setTotle_price(price.multiply(new BigDecimal(snOrderInlog.getNum())));
		boolean temp = service.save(snOrderInlog);
		if (temp) {
			renderJson(success(SAVE_SUCCESS_MSG));
		} else {
			renderJson(error(SAVE_FAIL_MSG));
		}
	}
	@ClearShiro
	public void update() {
		SnOrderInlog snOrderInlog = mapping(PERFIX, SnOrderInlog.class);
		boolean temp = service.update(snOrderInlog);
		if (temp) {
			renderJson(success(UPDATE_SUCCESS_MSG));
		} else {
			renderJson(error(UPDATE_FAIL_MSG));
		}
	}
	@ClearShiro
	public void remove() {
		String ids = getPara("ids");
		int cnt = service.deleteByIds(ids);
		if (cnt > 0) {
			renderJson(success(DEL_SUCCESS_MSG));
		} else {
			renderJson(error(DEL_FAIL_MSG));
		}
	}
}
